package me.android.library.common.orm;

import android.database.sqlite.SQLiteOpenHelper;

import com.google.common.base.Preconditions;

import lombok.Getter;
import lombok.Setter;
import me.android.library.common.orm.ability.Dao;
import mylab.base.foundation.lang.Identifiable;
import mylab.utils.common.ReflectUtil;
import mylab.utils.common.SqlStringUtil;

@Getter
public abstract class BaseDao<T extends Identifiable<Long>> implements Dao<T> {
    protected Class<T> entityClass;
    protected String tableName;
    @Setter
    protected SQLiteOpenHelper helper;

    public BaseDao(SQLiteOpenHelper helper) {
        entityClass = ReflectUtil.getGenericType(this.getClass(), 0);
        Preconditions.checkNotNull(entityClass, "泛型参数类型未指定:entityClass");
        tableName = SqlStringUtil.camelToUnderline(entityClass.getSimpleName());
        this.helper = helper;
    }

}
